<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
<!--    <script>if (window.top !== window.self) {-->
<!--        window.top.location = window.location;-->
<!--    }</script>-->

</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        
        <br/> 
        <h3>咨询回复</h3>
        
        <form class="m-t" role="form" action="login.html" style="text-align: left;">
            <div class="form-group">
            	<a style="font-size: 15px; color: black;">姓名</a><a style="color: red;"></a>
                <input disabled="disabled" type="text" id="name" class="form-control" placeholder="姓名" required="">
            </div>
            <div class="form-group">
            	<a style="font-size: 15px; color: black;">年龄</a><a style="color: red;"></a>
                <input disabled="disabled" type="number" id="age" class="form-control" placeholder="年龄" required="">
            </div>
            <div class="form-group">
            	<a style="font-size: 15px; color: black;">年龄</a><a style="color: red;"></a>
                <input disabled="disabled" type="text" id="sex" class="form-control" placeholder="性别" required="">
            </div>
            <div class="form-group">
            	<a style="font-size: 15px; color: black;">问题描述</a>
            	<a style="color: red;"></a>
            	<textarea disabled="disabled" style="height: 150px;" id="message" type="text" class="form-control" placeholder="病人症状" required=""></textarea>
            </div>
            <div class="form-group">
            	<a style="font-size: 15px; color: black;">回复内容</a>
            	<a style="color: red;">*</a>
            	<textarea style="height: 150px;" type="text" id="answer" class="form-control" placeholder="" required=""></textarea>
            </div>
            
            <br>
            <button type="button" id="submit" onclick="register()" class="btn btn-primary block full-width m-b">提 交
            </button>

        </form>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<!-- iCheck -->
<!--<script src="js/plugins/iCheck/icheck.min.js"></script>-->
<script src="./js/index.js"></script>
<script>
    $(document).ready(function () {
        getAQuestion();
    });


    function getAQuestion() {
        var ids = window.location.search;
        //将返回的字符串以=分割
        var id = ids.split("=")[1];
        $.ajax({
            async: false,
            type: "post",
            url: "/getAQuestion",
            data: JSON.stringify({id: id}),
            contentType: 'application/json',
            dataType: "text",
            success: function (data) {
                var result = JSON.parse(data);
                console.log(result);
                if (result.SUCCESS) {
                    appointmentInfo = result.RESULT;
                    afterInfo();
                } else {
                    console.log(result.RESULT);
                }
            },
            error: function (data) {
                alert("请求失败");
            }
        });
    }

    function afterInfo() {
        var name = $("#name");
        var age = $("#age");
        var sex = $("#sex");
        var message = $("#message");
        name.val(appointmentInfo.name);
        age.val(appointmentInfo.age);
        if (appointmentInfo.sex == 1) {
            sex.val("女");
        } else {
            sex.val("男");
        }
        message.val(appointmentInfo.message)
    }



    function register() {
            var answer = $("#answer").val().trim();
            if (answer == null) {
                alert("不可为空！");
                return false;
            }
            $.ajax({
                async: true,
                type: "post",
                url: "/updateQuestion",
                data: JSON.stringify(getQueryData()),
                contentType: 'application/json',
                dataType: "text",
                success: function (data) {
                    var result = JSON.parse(data);
                    console.log(result);
                    if (result.SUCCESS) {
                        alert(result.RESULT);
                        window.location.href = "/doctor-question.html";
                    } else {
                        alert(result.RESULT);
                    }
                },
                error: function (data) {
                    alert("请求失败");
                }
            });
    }


    function getQueryData() {
        var ids = window.location.search;
        //将返回的字符串以=分割
        var id = ids.split("=")[1];
        var dto = {};
        if (!ifEmpty($("#answer").val())) {
            dto["answer"] = $("#answer").val().trim();
        }
        dto["id"] = id;
        return dto;
    }


</script>


</body>

</html>
